/*
	Name: 
	Copyright: 
	Author: Quang
	Date: 11/03/14 10:37
	Description: Giai phuong trinh bac 2
*/
#include <conio.h>
#include <stdio.h>
#include <math.h>

// Nguyen mau ham
void gptBacHai(double, double, double);

int main(){
	double a,b,c;  // cac he so
	printf("Nhap 3 he so a,b,c lan luot: ");
	scanf("%lf%lf%lf",&a,&b,&c);
	
	gptBacHai(a,b,c);
	getch();
}

// Dinh nghia ham
// aX^2 + bx + c = 0
void gptBacHai(double a , double b, double c){
	if(a == 0){
		// Tro thanh phuong trinh bac nhat
		// bx + c = 0
		if(b == 0){ // c = 0
			if( c == 0){
				printf("\nPhuong trinh vo so nghiem");
			}
			else{
				printf("\nPhuong trinh vo nghiem");
			}
		}
		else{ // b != 0
			printf("\nPhuong trinh co nghiem la: %0.5lf",(-c/b));
		}
	}else{ // a != 0
		double delta = (b*b) - (4*a*c);
		if(delta < 0){
			printf("\n Phuong trinh vo nghiem");
		}else if(delta == 0){
			printf("\n Phuong trinh co nghiem kep la : %0.5lf",(-b/2*a));
		}else{ // delta > 0
			double x1 = (- b + sqrt(delta))/(2*a);
			double x2 = (- b - sqrt(delta))/(2*a);
			printf("\nPhuong trinh co hai nghiem phan biet la: ");
			printf("\n\tx1 = %0.5lf",x1);
			printf("\n\tx2 = %0.5lf",x2);
		}
	}
}
